
package com.du.limiting.sentinel.model;

public class HttpResponse<T> {
    private int code;
    private String msg;
    private Boolean success;
    protected T data;

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public HttpResponse(Boolean success, int code, String msg) {
        this.data = null;
        this.code = code;
        this.msg = msg;
        this.success = success;
    }

    public HttpResponse(Boolean success, T result, int code, String msg) {
        this.data = result;
        this.code = code;
        this.msg = msg;
        this.success = success;
    }

    public HttpResponse(Boolean success, int code, String msg, String redirectUrl) {
        this.code = code;
        this.msg = msg;
        this.success = success;
    }

    public HttpResponse() {
    }

    public static <T> HttpResponse<T> ok() {
        return new HttpResponse(true, 200, (String)null);
    }

    public static <T> HttpResponse<T> ok(T result) {
        return new HttpResponse(true, result, 200, (String)null);
    }

    public static <T> HttpResponse<T> fail(int code, String msg) {
        return new HttpResponse(false, code, msg);
    }

    public static <T> HttpResponse<T> fail(int code, String msg, String redirectUrl) {
        return new HttpResponse(false, code, msg, redirectUrl);
    }

    public static <T> HttpResponse<T> fail(int code, String msg, Throwable e) {
        return new HttpResponse(false, code, msg);
    }

}
